<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the timezone offset from GMT</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetimezone.getname.html">DateTimeZone::getName</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetimezone.gettransitions.html">DateTimeZone::getTransitions</a></div>
 <div class="up"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="datetimezone.getoffset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeZone::getOffset</h1>
  <h1 class="refname">timezone_offset_get</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0)</p><p class="refpurpose"><span class="refname">DateTimeZone::getOffset</span> -- <span class="refname">timezone_offset_get</span> &mdash; <span class="dc-title">Returns the timezone offset from GMT</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-datetimezone.getoffset-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><strong>DateTimeZone::getOffset</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$datetime</code></span>
   )</div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><a href="function.timezone-offset-get.html" class="methodname">timezone_offset_get</a></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$object</code></span>
   , <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$datetime</code></span>
   )</div>

  <p class="para rdfs-comment">
   This function returns the offset to GMT for the date/time specified in the
   <em><code class="parameter">datetime</code></em> parameter. The GMT offset is calculated
   with the timezone information contained in the DateTimeZone object being used.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimezone.getoffset-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<em><code class="parameter">
object</code></em></dt>
<dd>
<p class="para">仅过程化风格：由 <span class="function"><a href="function.timezone-open.html" class="function">timezone_open()</a></span> 返回的
<a href="class.datetimezone.html" class="classname">DateTimeZone</a> 对象。</p></dd>

    
     <dt>
<em><code class="parameter">datetime</code></em></dt>

     <dd>

      <p class="para">
       DateTime that contains the date/time to compute the offset from. 
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimezone.getoffset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns time zone offset in seconds on success 或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimezone.getoffset-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2215">
    <p><strong>Example #1 <span class="function"><strong>DateTimeZone::getOffset()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;two&nbsp;timezone&nbsp;objects,&nbsp;one&nbsp;for&nbsp;Taipei&nbsp;(Taiwan)&nbsp;and&nbsp;one&nbsp;for<br />//&nbsp;Tokyo&nbsp;(Japan)<br /></span><span style="color: #0000BB">$dateTimeZoneTaipei&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">"Asia/Taipei"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dateTimeZoneJapan&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">"Asia/Tokyo"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;two&nbsp;DateTime&nbsp;objects&nbsp;that&nbsp;will&nbsp;contain&nbsp;the&nbsp;same&nbsp;Unix&nbsp;timestamp,&nbsp;but<br />//&nbsp;have&nbsp;different&nbsp;timezones&nbsp;attached&nbsp;to&nbsp;them.<br /></span><span style="color: #0000BB">$dateTimeTaipei&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"now"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dateTimeZoneTaipei</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$dateTimeJapan&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"now"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dateTimeZoneJapan</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Calculate&nbsp;the&nbsp;GMT&nbsp;offset&nbsp;for&nbsp;the&nbsp;date/time&nbsp;contained&nbsp;in&nbsp;the&nbsp;$dateTimeTaipei<br />//&nbsp;object,&nbsp;but&nbsp;using&nbsp;the&nbsp;timezone&nbsp;rules&nbsp;as&nbsp;defined&nbsp;for&nbsp;Tokyo<br />//&nbsp;($dateTimeZoneJapan).<br /></span><span style="color: #0000BB">$timeOffset&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dateTimeZoneJapan</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOffset</span><span style="color: #007700">(</span><span style="color: #0000BB">$dateTimeTaipei</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Should&nbsp;show&nbsp;int(32400)&nbsp;(for&nbsp;dates&nbsp;after&nbsp;Sat&nbsp;Sep&nbsp;8&nbsp;01:00:00&nbsp;1951&nbsp;JST).<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$timeOffset</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="datetimezone.getname.html">DateTimeZone::getName</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="datetimezone.gettransitions.html">DateTimeZone::getTransitions</a></div>
 <div class="up"><a href="class.datetimezone.html">DateTimeZone</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
